<template>
	<view class="content">
		<Header>委员通</Header>
		<view class="search-content">
			<uni-search-bar @confirm="search" v-model="keywords" :focus="true" clearButton="auto" cancelButton="none" placeholder="请输入关键字" class="search-bar"></uni-search-bar>
			<view class="search-btn" @click="search">搜索</view>
		</view>
		<scroll-view style="height: calc(100vh - 105px);" scroll-y="true" @scrolltolower="lowerBottom">
			<uni-list>
				<uni-list-item direction="row" v-for="item in data" :key="item.id" >
					<template v-slot:header>
						<view class="uni-thumb">
							<image :src="item.avatar" mode="aspectFill" style="width: 100%;height: 100%;"></image>
						</view>
					</template>
					<template v-slot:body>
						<view class="uni-list-box uni-content">
							<view class="title uni-ellipsis-2">
								{{item.nickname}}
							</view>
							<view class="unit">
								{{item.mobile}}
							</view>
							<view class="unit">
								{{item.unit_name}}
							</view>
						</view>
					</template>
				</uni-list-item>
			</uni-list>
			<uni-load-more v-if="showLoad" :status="loadStatus" />
			<image src="https://zhzx.on-line-demo.com/image/zwsj.png" mode="aspectFit" class="no-data"
				v-if="loadStatus == 'no-more' && data.length == 0"></image>
		</scroll-view>
	</view>
</template>

<script>
	import Header from '../../components/header.vue'
	import request from '../../common/request.js'
	export default {
		components: {
			Header
		},
		data() {
			return {
				data: [],
				page: 1,
				loadStatus: 'loading',
				showLoad: false,
				keywords:''
			}
		},
		mounted() {
			this.getListData()
		},
		methods: {
			search(){
				this.data = []
				this.page = 0
				this.getListData()
			},
			lowerBottom() {
				if (this.loadStatus != 'loading') {
					this.loadStatus = 'loading'
					this.showLoad = true
					this.page++
					this.getListData()
				}
			},
			getListData() {
				request({
					url: '/user/addressBook',
					data: {
						keywords: this.keywords,
						page: this.page
					},
					method: 'POST',
				}).then(res => {
					if (res.code == 1) {
						this.data = this.data.concat(res.data)
						if (this.page == res.lastPage) {
							this.loadStatus = 'no-more'
						} else {
							this.loadStatus = 'more'
							this.showLoad = false
						}
					} else {
						this.loadStatus = 'no-more'
					}
				})
			},
		}
	}
</script>

<style scoped>
	.search-content{
		display: flex;
		align-items: center;
		width: 100%;
	}
	.search-bar{
		width: calc(100% - 60px);
	}
	::v-deep .uni-searchbar__box{
		border: 1px solid #898989;
		height: 40px;
		background-color: transparent !important;
	}
	.uni-thumb{
		width: 60px;
		height: 60px;
		border-radius: 50%;
	}
	.uni-list-box{
		justify-content: center;
	}
	.title{
		/* font-weight: bold; */
		margin-bottom: 5px;
	}
	.unit{
		font-size: 14px;
		/* color: #898989; */
	}
</style>